package com.cmes.system.web.controller;

import com.cmes.core.Pagination;
import com.cmes.core.context.security.SecurityContextHolder;
import com.cmes.jdbc.customquery.CustomQueryBO;
import com.cmes.system.core.entity.LoginLogEntity;
import com.cmes.system.core.service.LoginLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 部门管理
 *
 * @author Bruce.Gong
 * @since 1.0.0-SNAPSHOT
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/loginLogin")
public class LoginLogController {

    private final LoginLogService loginLogService;

    @PostMapping("search")
    public Pagination<LoginLogEntity> search(@RequestBody @Valid CustomQueryBO bo) {
        Long userId = SecurityContextHolder.getCurrentUserId();
        return loginLogService.page(bo, w -> w.lambda().setEntityClass(LoginLogEntity.class)
                .eq(LoginLogEntity::getUserId, userId)
                .orderByDesc(LoginLogEntity::getLoginTime));
    }

}
